'
倒计时管理器，控制难度，倒计时结束时胜利
'

extends Node

const DIFFICULTY_INTVAL = 5#难度增加间隔
#难度信号：难度等级
signal arena_difficulty_increased(arena_difficulty: int)

@onready var timer = $Timer

@export var end_screen_scene: PackedScene

var arena_difficulty = 0#难度等级


func _ready() -> void:
	timer.timeout.connect(on_timer_timeout)
	pass

#每5秒增加一级难度
func _process(_delta: float) -> void:
	var next_time_target = timer.wait_time - ((arena_difficulty + 1) * DIFFICULTY_INTVAL)
	if timer.time_left <= next_time_target:
		arena_difficulty += 1
		arena_difficulty_increased.emit(arena_difficulty)
	pass

#返回计时器过去的时间
func get_time_elapsed() -> float:
	return timer.wait_time - timer.time_left

#倒计时结束胜利
func on_timer_timeout() -> void:
	var end_screen_instance = end_screen_scene.instantiate()
	self.get_parent().add_child(end_screen_instance)
	end_screen_instance.set_ending()
	pass
